<?php
namespace App\Http\Controllers\Admin;

use App\Service\Admin\TaskService;
use App\Utility\Upload;
use Illuminate\Http\Request;

class TaskController extends BaseController
{
    //登录

    //获取权限
    public function index(Request $request)
    {
        $pages['start'] = $request->post('start', 1);
        $pages['limit'] = $request->post('limit', 10);
        $pas['sort_id'] = $request->post('sort_id', 0);
        $pas['depart_id'] = $request->post('depart_id', 0);
        $res = TaskService::index($pages, $pas);
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson(0, '', $res['data'], $res['total']);
    }

    //修改
    public function modify(Request $request)
    {
        $id = $request->post('id', 0);
        $pas['role_id'] = $request->post('role_id', 0);
        $pas['depart_id'] = $request->post('depart_id', 0);
        $pas['staff_id'] = $request->post('uid', 0);
        $pas['title'] = $request->post('title', '');
        $pas['title'] = $request->post('title', '');
        $pas['detail'] = $request->post('detail', '');
        $pas['in_day'] = $request->post('in_day', '');
        if ($pas['in_day']) {
            $pas['in_day'] = date('Y-m-d', strtotime($pas['in_day']));
        }
        if ($id) {
            $res = TaskService::modify($id, $pas);
        } else {
            $res = TaskService::add($pas);
        }
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson();
    }

    //删除
    public function del(Request $request)
    {
        $id = $request->post('id', 0);
        $res = TaskService::del($id);
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson();
    }
}